import tfidf
import load
import matplotlib.pyplot as plt

allStar=[]

for i in range(1, load.allNum):
    try:
        star=int(load.getCellT1(i, load.star))
    except:
        continue
    if star>5 or star<1:
        continue
    tfidf.allReviewText.append(load.getReviewText(i))
    allStar.append(star)

def readDict(path):
    content=load.readFile(path)
    return content.split('\n')

poswords=readDict('正面情感词语（英文）.txt')+readDict('正面评价词语（英文）.txt')
negwords=readDict('负面评价词语（英文）.txt')+readDict('负面情感词语（英文）.txt')

allPosNum=[]
for review in tfidf.allReviewText:
    pos=0
    for pi in poswords:
        if review.find(pi)!=-1:
            print(pi)
            pos+=1
    for ni in negwords:
        if review.find(ni)!=-1:
            print(ni)
            pos-=1
    allPosNum.append(pos)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(allPosNum,allStar,c='blue')
plt.show()